package 蓝桥杯;

import java.util.Scanner;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/11/17
 */
public class 进制转换 {

    static int N = 20; // 数据范围
    static int n; // 元素个数
    static String[] s = new String[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        for (int i = 0; i < n; i++) {  // 初始化
            String in = scanner.next();
            while (in.charAt(0) == '0') {
                in = in.substring(1);
            }
            s[i] = in;
        }


        for (int i = 0; i < n; i++) {
            if (s[i].length() <= 100000) {
                int temp = Integer.parseInt(s[i], 16); // 16 转 10；
                String s = Integer.toOctalString(temp);
                while (s.charAt(0) == '0') {
                    s = s.substring(1);
                }
                System.out.println(s); // 10 转 8
            }
        }
    }
}
